package example.strategy.spring;

import org.apache.log4j.Logger;
import com.scop.desensitize.exception.strategy.DecodeException;
import com.scop.desensitize.exception.strategy.EncodeException;
import com.scop.desensitize.posterity.AbstractPosterity;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

/**
 * @desc springbean的使用示例
 */
public class SpringBeanDemo {
	public static Logger log = Logger.getLogger(SpringBeanDemo.class);
	public static void main(String[] args) throws EncodeException, DecodeException {
		ClassPathResource rs=new ClassPathResource("applicationContext.xml");
		XmlBeanFactory xmlBeanFactory=new XmlBeanFactory(rs);
		AbstractPosterity encry = (AbstractPosterity) xmlBeanFactory.getBean("stringDesensitization");

		String data = "scop";
		//加密
		String abcEnStr = (String) encry.encode(data);
		//解密
		String abcDeStr = (String) encry.decode(abcEnStr);

		log.info("自定义密码加密--->默认数据：" + data);
		log.info("自定义密码加密--->加密之后：" + abcEnStr);
		log.info("自定义密码加密--->解密之后：" + abcDeStr);
	}

    
}
